/** Interactive Surface  FYP- 25 Interactive Surface FYP- 25 Interactive Surface FYP- 25
 *
 *  @author Acer
 */
package controller;

import camera.Camera;
import insurface.InteractiveSurface;
import java.util.Arrays;
import utilities.CoordinateFinder;

/** Interactive Surface FYP- 25 Interactive Surface FYP- 25 Interactive Surface FYP- 25
 *  General Information about this class -
 *  Comments -
 */
public abstract class Controller implements Runnable {

    final int CAM_NUM1, CAM_NUM2, CAM_FOV = 84;
    InteractiveSurface inSurface;
    public boolean isConsecutive = false;
    CoordinateFinder coFind = new CoordinateFinder();
    Camera cam1, cam2;
    Thread th1, th2;
    boolean gettingLast = false;
    boolean finishedY = false;
    public boolean camActive = true;
    //used to find the last Y coordinate
    int[] yVal1 = new int[50];
    int[] yVal2 = new int[50];
    int count = 0;

    public Controller(int CAM_NUM1, int CAM_NUM2, InteractiveSurface ins) {
        this.CAM_NUM1 = CAM_NUM1;
        this.CAM_NUM2 = CAM_NUM2;
        this.inSurface = ins;
    }

    public void setActive(boolean dr) {
        cam1.setActive(dr);
        cam2.setActive(dr);
        camActive = dr;
    }

    /**
     * @return the getLastPoint
     */
    public boolean isGettingLast() {
        return gettingLast;
    }

    /**
     * @param getLastPoint the getLastPoint to set
     */
    public void setGettingLast(boolean getLastPoint) {
        this.gettingLast = getLastPoint;
        if (!getLastPoint) {
            count = 0;
            yVal1 = new int[50];
            yVal2 = new int[50];
        }
    }

    /**
     * @return the finishedY
     */
    public boolean isFinishedY() {
        return finishedY;
    }

    public void setYLast() {
        Arrays.sort(yVal1);
        Arrays.sort(yVal2);
        int tot1 = 0, tot2 = 0;
        if (yVal1[35] - yVal1[26] > 20) {
            yVal1 = new int[50];
            yVal2 = new int[50];
            count = 0;
            System.out.println("missed at 1");
            return;
        }

        if (yVal2[35] - yVal2[26] > 20) {
            yVal1 = new int[50];
            yVal2 = new int[50];
            count = 0;
            System.out.println("missed at 2");
            return;
        }

        for (int h = 26; h <= 35; h++) {
            tot1 = tot1 + yVal1[h];
            tot2 = tot2 + yVal2[h];
        }
        tot1 = tot1 / 10;
        tot2 = tot2 / 10;
        gettingLast = false;
        finishedY = true;
        count = 0;
        yVal1 = new int[50];
        yVal2 = new int[50];
        count = 0;
        System.out.println("CALIBRATED camera 1=" + tot1 + " Camera 2=" + tot2);
        cam1.setLastY(tot1);
        cam2.setLastY(tot2);
    }
}
